#ifndef COMPILEROPTIONSDLG_H
#define COMPILEROPTIONSDLG_H

#include <vector>
#include <wx/intl.h>
#include <wx/string.h>
#include "configurationpanel.h"
#include "compileroptions.h"
#include "scrollingdialog.h"
#include <wx/string.h>
#include "compiler.h"

class wxListBox;
class ScopeTreeData;
class M_Code_Project;
class ProjectBuildTarget;
class CompilerGCC;
class wxSpinEvent;
class wxTreeEvent;
class wxCommandEvent;
class wxKeyEvent;
class wxPropertyGrid;
class wxPropertyGridEvent;
class wxUpdateUIEvent;

class CompilerOptionsDlg : public cbConfigurationPanel {
  public:
    CompilerOptionsDlg( wxWindow* parent, CompilerGCC* compiler, M_Code_Project* project = 0L, ProjectBuildTarget* target = 0L );
    ~CompilerOptionsDlg();
    virtual wxString GetTitle() const { return _T( "编译器参数" ); }
    virtual wxString GetBitmapBaseName() const { return _T( "compiler" ); }
    bool IsDirty() const { return m_bDirty; }
    virtual void OnApply();
    virtual void OnCancel() {}
  private:
    enum CustomVarActionType {
      CVA_Add,
      CVA_Edit,
      CVA_Remove
    };
    struct CustomVarAction {
      CustomVarActionType m_Action;
      wxString m_Key;
      wxString m_KeyValue;
    };
    void TextToOptions();
    void OptionsToText();
    void DoFillCompilerSets( int compilerIdx );
    void DoFillCompilerPrograms();
    void DoFillVars();
    void DoFillOthers();
    void DoFillOptions();
    void DoFillCompilerDependentSettings();
    void DoSaveCompilerDependentSettings();
    void DoFillTree();
    void DoSaveOptions();
    void DoLoadOptions();
    void DoSaveCompilerPrograms();
    void DoSaveVars();
    void DoSaveCompilerDefinition();
    void CompilerChanged();
    void UpdateCompilerForTargets( int compilerIdx );
    void AutoDetectCompiler();
    wxListBox* GetDirsListBox();
    CompileOptionsBase* GetVarsOwner();
    void ProjectTargetCompilerAdjust();
    void OnRealApply();
    void OnTreeSelectionChange( wxTreeEvent& event );
    void OnTreeSelectionChanging( wxTreeEvent& event );
    void OnCompilerChanged( wxCommandEvent& event );
    void OnCategoryChanged( wxCommandEvent& event );
    void OnOptionChanged( wxPropertyGridEvent& event );
    void OnAddDirClick( wxCommandEvent& event );
    void OnEditDirClick( wxCommandEvent& event );
    void OnRemoveDirClick( wxCommandEvent& event );
    void OnClearDirClick( wxCommandEvent& event );
    void OnCopyDirsClick( wxCommandEvent& event );
    void OnAddVarClick( wxCommandEvent& event );
    void OnEditVarClick( wxCommandEvent& event );
    void OnRemoveVarClick( wxCommandEvent& event );
    void OnClearVarClick( wxCommandEvent& event );
    void OnSetDefaultCompilerClick( wxCommandEvent& event );
    void OnAddCompilerClick( wxCommandEvent& event );
    void OnEditCompilerClick( wxCommandEvent& event );
    void OnRemoveCompilerClick( wxCommandEvent& event );
    void OnResetCompilerClick( wxCommandEvent& event );
    void OnMoveDirUpClick( wxCommandEvent& event );
    void OnMoveDirDownClick( wxCommandEvent& event );
    void OnMasterPathClick( wxCommandEvent& event );
    void OnAutoDetectClick( wxCommandEvent& event );
    void OnSelectProgramClick( wxCommandEvent& event );
    void OnAdvancedClick( wxCommandEvent& event );
    void OnAddExtraPathClick( wxCommandEvent& event );
    void OnEditExtraPathClick( wxCommandEvent& event );
    void OnRemoveExtraPathClick( wxCommandEvent& event );
    void OnClearExtraPathClick( wxCommandEvent& event );
    void OnIgnoreAddClick( wxCommandEvent& event );
    void OnIgnoreRemoveClick( wxCommandEvent& event );
    void OnUpdateUI( wxUpdateUIEvent& event );
    void OnDirty( wxCommandEvent& event );
    void OnMyCharHook( wxKeyEvent& event );
    void OnFlagsPopup( wxPropertyGridEvent& event );
    void OnFlagsPopupClick( wxCommandEvent& event );
    void OnOptionDoubleClick( wxPropertyGridEvent& event );
  private:
    wxPropertyGrid* m_FlagsPG;
    CompilerGCC* m_Compiler;
    CompilerOptions m_Options;
    wxArrayString m_LinkerOptions;
    wxArrayString m_LinkLibs;
    wxArrayString m_CompilerOptions;
    wxArrayString m_ResourceCompilerOptions;
    int m_CurrentCompilerIdx, xml_File_lock;
    M_Code_Project* m_pProject;
    ProjectBuildTarget* m_pTarget;
    bool m_bDirty;
    bool m_bFlagsDirty;
    std::vector<CustomVarAction> m_CustomVarActions;
    wxString m_NewProjectOrTargetCompilerId;
    bool m_BuildingTree;
    static int m_MenuOption;

    void OnCommandsChange( wxCommandEvent& event );
    void OnExtChange( wxCommandEvent& event );
    void OnAddExt( wxCommandEvent& event );
    void OnDelExt( wxCommandEvent& event );
    void OnRegexChange( wxCommandEvent& event );
    void OnRegexTest( wxCommandEvent& event );
    void OnRegexAdd( wxCommandEvent& event );
    void OnRegexDelete( wxCommandEvent& event );
    void OnRegexDefaults( wxCommandEvent& event );
    void OnRegexUp( wxSpinEvent& event );
    void OnRegexDown( wxSpinEvent& event );
    void EndModal( int retCode );
    void CheckCompilerOptions(bool type = false);
    void ReadExtensions( int nr );
    void DisplayCommand( int cmd, int ext );
    void CheckForChanges();
    CompilerTool* GetCompilerTool( int cmd, int ext );
    void SaveCommands( int cmd, int ext );
    void FillRegexes();
    void FillRegexDetails( int index );
    void SaveRegexDetails( int index );
    wxString m_CompilerId;
    int m_LastCmdIndex;
    int m_LastExtIndex;
    RegExArray m_Regexes;
    int m_SelectedRegex;
    CompilerToolsVector m_Commands[ctCount];

    DECLARE_EVENT_TABLE()
};

#endif
